package com.neu.questionnaire_system.controller;


import com.neu.questionnaire_system.beans.ResponseEntity;
import com.neu.questionnaire_system.service.QuestionService;
import com.neu.questionnaire_system.service.impl.QuestionServiceImpl;
import com.neu.questionnaire_system.service.impl.QuestionnaireServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xingle
 * @since 2022-11-07
 */
@RestController
@RequestMapping("/question")
@CrossOrigin
public class QuestionController {
    @Autowired
    private QuestionServiceImpl questionService;

    @RequestMapping("/insertQuestion")
    public ResponseEntity insertQuestion(String qid, String questionType, String questionText) {
        return questionService.insertQuestion(qid, questionType, questionText);
    }

    @RequestMapping("/selectQuestionByQid")
    public ResponseEntity selectQuestionByQid(String qid) {
        return questionService.selectQuestionByQid(qid);
    }

    @RequestMapping("/updateQuestion")
    public ResponseEntity updateQuestion(String questionId, String questionType, String questionText) {
        return questionService.updateQuestion(questionId, questionType, questionText);
    }

    @RequestMapping("deleteQuestion")
    public ResponseEntity deleteQuestion(String questionId) {
        return questionService.deleteQuestion(questionId);
    }

    @RequestMapping("/showAllQuestion")
    public ResponseEntity showAllQuestion() {
        return questionService.showAllQuestion();
    }

    @RequestMapping("/jumpToQuestion")
    public ResponseEntity jumpToQuestion(String choiceId) {
        return questionService.jumpToQuestion(choiceId);
    }

    /**
     * created by libo 题目统计
     * question 题目的信息，键与数据库属性对应
     * answerChoice包含选择题每个选项的合计人数num，题号count和选项answerContent,占比percentage
     * questionBlock包含填空题填写的信息answerContent和题号count
     *
     * @param map 包含问卷的qid
     * @return 封装信息的统一的返回对象
     */
    @RequestMapping("/quesStatistics")
    public ResponseEntity answerChoice(@RequestBody Map<String, Object> map) {
        return questionService.quesStatistics(map);
    }


}
